<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>注册</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link type="text/css" href="/css/hmstyle.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/AmazeUI-2.4.2/assets/css/amazeui.min.css"/>
    <link href="/css/dlstyle.css" rel="stylesheet" type="text/css">
    <link href="/layui/css/layui.css" rel="stylesheet" type="text/css">
    <script src="/AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="/AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script src="/js/common.js" type="text/javascript"></script>
</head>

<body>


<div class="res-banner">
    <div class="res-main">
        <div class="login-box">

            <div class="am-tabs" id="doc-my-tabs">
                <ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
                    <li><a href="">手机号注册</a></li>
                </ul>

                <div class="am-tabs-bd">


                    <div class="am-tab-panel">
                        <form class="layui-form" id="form1" lay-filter="form1">
                            <div class="user-phone">
                                <label for="tel"><i class="am-icon-mobile-phone am-icon-md"></i></label>
                                <input type="tel" name="tel" id="tel" placeholder="请输入手机号">
                            </div>
                            <div class="verification">
                                <label for="code"><i class="am-icon-code-fork"></i></label>
                                <input type="tel" name="code" id="code" placeholder="请输入验证码">
                                <a class="btn" id="sendBtn"><span id="sendBtn2">获取</span></a>
                            </div>
                            <div class="user-pass">
                                <label for="password"><i class="am-icon-lock"></i></label>
                                <input type="password" name="password1" id="password" placeholder="设置密码">
                            </div>
                            <div class="user-pass">
                                <label for="passwordRepeat"><i class="am-icon-lock"></i></label>
                                <input type="password" name="password2" id="passwordRepeat" placeholder="确认密码">
                            </div>
                        </form>
                        <div class="login-links">
                            <label for="reader-me">
                                <input id="reader-me" type="checkbox"> 点击表示您同意商城《服务协议》
                            </label>
                        </div>
                        <div class="am-cf">
                            <input type="submit" id="register" name="register" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl">
                            <a href="/login"><input type="button" id="login" name="login" value="登录" class="am-btn am-btn-primary am-btn-sm am-fl"></a>
                        </div>

                        <hr>
                    </div>

                    <script>
                        $(function () {
                            $('#doc-my-tabs').tabs();
                        })
                    </script>

                </div>
            </div>

        </div>
    </div>
</div>
<th:block th:include="footer"/>
<script th:inline="javascript">
    layui.use(["layer","form","laytpl"],function (){
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;
        var msg = [[${msg}]];
        if(msg){
            layer.msg(msg,{
                icon:2,
                time:2000
            });
        }

        $("#sendBtn").on("click",function (){
            var tel = $("#tel").val();
            console.log(tel);
            if(!tel){
                layer.msg("请输入手机号");
                return false;
            }
            var m = 60;
            var timer = null;
            var f = function (){
                m -= 1;
                if(m ===0){
                    $("#sendBtn").text("重新发送");
                    $("#sendBtn").prop("disabled",false);
                    clearInterval(timer);
                }else {
                    $("#sendBtn").text("重新发送" + m + "s");
                }
            };
            $.post("/register/sendCode",{tel:tel},function (){
                $("sendBtn").prop("disabled",true);
                timer = setInterval(f,1000);
            });

        });

        $("#register").on("click",function (){
            var data = form.val("form1")
            console.log(data);
            console.log(data.password1);
            if (!data.password1) {
                layer.msg("密码不能为空!")
                return false;
            }else if(!data.code){
                layer.msg("验证码不能为空!")
                return false;
            }else if(data.password1 !== data.password2){
                layer.msg("两次输入密码不一致！")
                return false;
            }

            $.post("/register/registerSuccess", data, function () {
                layer.msg("注册成功!，请您登录")
            })
        })
        $("#login").on("click",function (){
            $.get("/login",function (){

            });
        });
    });
</script>
</body>

</html>